<template>
	<view class="tree-node">
		<!-- 根节点 -->
		<block v-for="(item, index) in data" :key="index">
			<tree-node :node="item" @toggle="onToggle" :props="props.props" @handleAdd="handleAdd" @handleEdit="handleEdit" @handleDelete="handleDelete"></tree-node>
		</block>
	</view>
</template>

<script setup>
	import {
		ref,
		defineEmits
	} from 'vue';
	import TreeNode from './TreeNode.vue'; // 引入子节点组件

	const props = defineProps({
		data: {
			type: Array,
			required: true
		},
		props: {
			type: Object,
			default: () => ({})
		}
	});

	const onToggle = (node) => {
		node.open = !node.open;
	};
	
	const emit = defineEmits(['handleAdd', 'handleEdit', 'handleDelete']);
	
	const handleAdd = (node) => {
		emit('handleAdd', node)
	}
	
	const handleEdit = (node) => {
		emit('handleEdit', node)
	}
	
	const handleDelete = (node) => {
		emit('handleDelete', node)
	}
	
</script>

<style>
</style>